﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Lab_Master_Detail_Table : frmBaseChild
    {

        //gridView 主从表实现
        //https://www.bbsmax.com/A/Vx5M1Meg5N/

        //Dev中GridControl构建主从表，三种方式构建表（数据源为DataSet、List<T>、SQL)
        //https://blog.csdn.net/qq_33459369/article/details/80006845

        public frmMES_Lab_Master_Detail_Table()
        {
            InitializeComponent();
        }

        private void frmMES_Lab_Master_Detail_Table_Load(object sender, EventArgs e)
        {
            DataTable dt1 = new DataTable("dt1");//表1
            DataTable dt2 = new DataTable("dt2");//表2

            dt1.Columns.Add("A", typeof(int));
            dt1.Columns.Add("B");
            dt1.Columns.Add("C");

            for (int i = 0; i < 8; i++)
            {
                dt1.Rows.Add(i  , "测试数据", "测试内容");
            }

            dt2.Columns.Add("A", typeof(int));
            dt2.Columns.Add("E");
            dt2.Columns.Add("F");

            for (int i = 0; i < 4; i++)
            {
                dt2.Rows.Add(i , "子表数据", "子表内容");
            }

            DataSet ds = new DataSet();
            ds.Tables.Add(dt1);
            ds.Tables.Add(dt2);

            DataRelation relation = new DataRelation("子表内容", 
                ds.Tables["dt1"].Columns["A"], 
                ds.Tables["dt2"].Columns["A"]);//这个Level2要与GridView的关系相同

            ds.Relations.Add(relation);

            gridControl1.DataSource = ds.Tables["dt1"];
        }

        private void menuItemCollapseAllDetails_Click(object sender, EventArgs e)
        {
            (gridControl1.MainView as DevExpress.XtraGrid.Views.Grid.GridView).CollapseAllDetails(); //要折叠主视图中的所有主控行
        }
    }
}